package org.taobao.ibatiside.ui.action;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.taobao.ibatiside.core.filemodel.IbatisStatement;
import org.taobao.ibatiside.ui.Activator;
import org.taobao.ibatiside.ui.util.Mapper2XMLProcessor;

public class OverviewDeleteStmtAction extends OverviewDeleteAction {
	public static final String ID="org.taobao.ibatiside.ui.action.iov.deletestmt";
	public OverviewDeleteStmtAction() {
		super();
		setId(ID);
		setText("Delete Statement");
		setImageDescriptor(Activator.getIcon("op16/erase.png"));
	}
	@Override
	protected boolean doDelete() {
		IbatisStatement stmt = (IbatisStatement) getSelectObject();
		viewer.remove(stmt);
		IFile mapper_file = (IFile) stmt.getParent().getResource();
		if (mapper_file.isAccessible()){
			Mapper2XMLProcessor processor = new Mapper2XMLProcessor();
			processor.removeStmt(mapper_file, stmt.getId());
			try {
				mapper_file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}
		return true;
	}
	
}
